package mid.序列问题.摆动序列;

/**
 * @author zhengTao
 * @version 1.0
 * @description: mid.序列问题.摆动序列,想不到！！！！！！！！！！！
 * @date 2022/11/20 10:51
 */
public class Demo376 {
    public static void main(String[] args) {
        int[] nums={1,17,5,10,13,15,10,5,16,8};
        int i = wiggleMaxLength(nums);
        System.out.println(i);
    }
    public static int wiggleMaxLength(int[] nums) {
        if(nums.length<=2){
            return 2;
        }
        int up = 1;
        int down = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                up = down + 1;
            }
            if (nums[i] < nums[i - 1]) {
                down = up + 1;
            }
        }
        return Math.max(up, down);
    }

}
